package apIExercise.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class CollectionToArray {
    public static void main(String[] args) {
        //若参数数组元素个数==集合元素个数，那就正常转换
        //若参数数组元素个数<集合元素个数，那也正常转换(按照集合大小给数组)
        //若参数数组元素个数>集合元素个数，那也正常转换，同时在末尾补默认值

        //集合转数组
        Collection<String> c=new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        System.out.println(c);
        String[] array=c.toArray(new String[5]);
        System.out.println(Arrays.toString(array));

        Collection<Double> c1=new ArrayList<>();
        c1.add(1.1);
        c1.add(2.2);
        c1.add(3.3);
        System.out.println(c1);
        Double[] array1=c1.toArray(new Double[c1.size()]);
        System.out.println(Arrays.toString(array1));

    }
}
